﻿@{
    Layout = "_LayoutH";
    @model Wms_material
}
<div id="app" v-cloak>
    <form class="form-horizontal" onsubmit="return false">
        <div class="box-body">
            <div class="form-group">
                <label class="col-sm-2 control-label">物料名称</label>
                <div class="col-sm-10">
                    <input class="form-control" v-model="MaterialName" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">单位</label>
                <div class="col-sm-10">
                    <input class="form-control" v-model="Unit" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2"><span class="c-red">*</span>使用范围</label>
                <div class="col-sm-10 ">
                    <label class="radio-inline">
                        <input type="radio" value="0" v-model="Source">全部
                    </label>
                    <label class="radio-inline">
                        <input type="radio" value="1" v-model="Source">入库
                    </label>
                    <label class="radio-inline">
                        <input type="radio" value="2" v-model="Source">出库
                    </label>
                </div>
            </div>
        </div>
        <div class="box-footer">
            <div class="pull-right box-tools">
                <input v-on:click="addL" class="btn btn-primary radius" type="submit" v-model="submit">
            </div>
        </div>
    </form>
</div>
@section scripts{
    <script>
        //v-on:input="$emit('input', $event.target.value)"
        var app = new Vue({
            el: "#app",
            data: {
                submit: "添加",
                Remark: "@Model.Remark",
                MaterialId:"@Model.MaterialId",
                MaterialName: "@Model.MaterialName",
                Unit: "@Model.Unit",
                Source:"@Model.Source",
            },
            computed: {
                count: function () {
                    return this.strLength(this.Remark, false);
                }
            },
            methods: {
                loadL: function (id,type) {
                    var _self = this;
                    if (type === 1) {
                        yui.$axiosget('/StorageRack/GetReservoirarea2?id=' + id).then(function (response) {
                            _self.rlist = response.data;
                        });
                    } else {
                        yui.$axiosget('/StorageRack/GetStoragerack?id=' + id).then(function (response) {
                            _self.slist = response.data;
                        });
                    }
                },
                addL: function () {
                    var _self = this;
                    if (_self.MaterialName.length <= 0) {
                        layer.msg("物料名称不能为空", { icon: 2 });
                        return false;
                    }

                    if (_self.Unit.length <= 0) {
                        layer.msg("请输入单位", { icon: 2 });
                        return false;
                    }
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var data = {
                        id: _self.MaterialId,
                        MaterialName: _self.MaterialName,
                        Unit: _self.Unit,
                        Source: _self.Source,
                        InOrderNo: 99,
                        OutOrderNo:99
                    };
                    yui.$axiospostform('/Material/AddOrUpdate', data)
                        .then(function (response) {
                            if (response.data.Item1 === 101) {
                                layer.tips(response.data.Item2, '.layui-layer-setwin', {
                                    tips: [1, '#3595CC'],
                                    time: 3000
                                });
                                layer.close(index);
                                return false;
                            }
                            if (response.data.Item1) {
                                layer.msg(response.data.Item2, { icon: 1, time: 1000 });
                                setTimeout(function () {
                                    yui.layer_close3();
                                }, 500);
                            } else {
                                layer.msg(response.data.Item2 || errorMsg, { icon: 5 });
                            }
                            layer.close(index);
                        })
                        .catch(function (error) {
                            layer.close(index);
                        });
                }
            }
        });
    </script>
}